package com.modemMgr.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBServer {
	//private static final Logger logger = Logger.getLogger(DBServer.class);
	private static String driver;
	private static String url;
	private static String userName;
	private static String password;

	static {
		InputStream stream = DBServer.class.getResourceAsStream("/jdbc.properties");
		Properties properties = new Properties();
		try {
			properties.load(stream);
			driver = properties.getProperty("driver");
			url = properties.getProperty("url");
			userName = properties.getProperty("userName");
			password = properties.getProperty("password");

			Class.forName(driver);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, userName, password);
	}
	
	public static DBAccessor newDBAccessor(boolean autoCommit) throws SQLException
	{
		Connection connection = getConnection();
		connection.setAutoCommit(autoCommit);
		return new DBAccessor(connection);
	}	
}
